package cc.picc;

import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cc.picc.quota.QuotaBucketSpec;
import cc.picc.quota.StringQuotaBucketContainer;

@Configuration
public class QuotaBucketConfig {
	public static final String BUCKET_NAME = RandomStringUtils.randomNumeric(8);

	/**
	 * 
	 * @return
	 */
	@Bean
	public StringQuotaBucketContainer stringQuotaBucketContainer() {
		return new StringQuotaBucketContainer(QuotaBucketSpec.builder().name(BUCKET_NAME).capacity(300).build());
	}

	/**
	 * @param quotaBucketContainer
	 * @return
	 */
	@Bean
	public QuotaPublisher quotaPublisher(StringQuotaBucketContainer quotaBucketContainer) {
		return new QuotaPublisher(quotaBucketContainer);
	}

	/**
	 * @param quotaBucketContainer
	 * @return
	 */
	@Bean
	public QuotaConsumer quotaConsumer(StringQuotaBucketContainer quotaBucketContainer) {
		return new QuotaConsumer(quotaBucketContainer);
	}
}
